//
//  JSLTabBarController.m
//  piggy
//
//  Created by 宋质彬 on 2018/6/19.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "JSLTabBarController.h"
#import "JSLHomeController.h"
#import "JSLLoanController.h"
#import "JSLProfileController.h"
#import "AppConfig.h"
#import "JSLBillHomeController.h"
@interface JSLTabBarController ()

@end

@implementation JSLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor redColor];
    
    // 配置tabbar样式
    [self settabBarAppearance];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

//    配置navbar样式
    [self setNavigationBarAppearance];
    
    // 配置tabbarController子视图
    [self configAllChildController];
}



- (void)configAllChildController {
    
    JSLHomeController *toolVC = [[JSLHomeController alloc] init];
    UINavigationController *toolItem = [self addChildNavigationVcWithImage:@"menu-icon1" title:@"首页" rootVc:toolVC];
    
    JSLLoanController *discoverVC = [[JSLLoanController alloc] init];
    UINavigationController *discoverItem = [self addChildNavigationVcWithImage:@"menu-icon2" title:@"产品大全" rootVc:discoverVC];
    
    JSLProfileController *profileVC = [[JSLProfileController alloc] init];
    UINavigationController *profileItem = [self addChildNavigationVcWithImage:@"menu-icon3" title:@"我的" rootVc:profileVC];
    
    
    JSLBillHomeController *billHomeVC = [[JSLBillHomeController alloc] init];
    UINavigationController *BillHomeItem = [self addChildNavigationVcWithImage:@"menu-icon4" title:@"叮当账单" rootVc:billHomeVC];
    
    if ([AppConfig shareConfig].audit) {
     
     self.viewControllers = @[BillHomeItem,profileItem];
    
    }else{
        self.viewControllers = @[toolItem,discoverItem,profileItem];
        
        
       
    }

    
}

- (UINavigationController *)addChildNavigationVcWithImage:(NSString*)image title:(NSString *)title rootVc:(UIViewController *)rootVc {
    
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:rootVc ];
    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSString * selectedImage = [NSString stringWithFormat:@"%@-hover",image];
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    return nav;
}

- (void)settabBarAppearance {
    
  
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],
                                                        NSForegroundColorAttributeName:[UIColor blackColor]}
                                             forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],
                                                        NSForegroundColorAttributeName:[@"#2BA6FF" hexStringToColor]}
                                             forState:UIControlStateSelected];
    
    
    [[UITabBar appearance] setBackgroundImage:[UIImage new]];
    [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tabbar_shadow"]];
    
    
    [UITabBar appearance].translucent = NO;
    
    [self.tabBar addSubview:[self ImageBlur]];
    
    
    
    
    
    
}

- (UIVisualEffectView *)ImageBlur{
    
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
    effectView.alpha =1;
    //    effectView.backgroundColor = [UIColor whiteColor];
    
    // 加上以下代码可以使毛玻璃特效更明亮点
    UIVibrancyEffect *vibrancyView = [UIVibrancyEffect effectForBlurEffect:effect];
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:vibrancyView];
    visualEffectView.translatesAutoresizingMaskIntoConstraints = NO;
    [effectView.contentView addSubview:visualEffectView];
    
    return effectView;
    
}

- (void)setNavigationBarAppearance{
    
    [[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[UIImage new]];
    [UINavigationBar appearance].translucent = NO;
    [UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName:[@"#4A4A4A" hexStringToColor]};;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
